<?php

?>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>LeeCms系统安装</title>
    <link rel="stylesheet" href="/<?php echo $basepath ?>/install/assert/install.css"/>
    <script type="text/javascript" src="/<?php echo $basepath ?>/assert/js/jquery.js"></script>
</head>
<body>
<div class="header">
    <div class="logo">LeeCms</div>
    <div class="step">
        <div class="line"></div>
        <ul class="step_num">
            <li class=""><span class="num">1</span>
                <p class="name">阅读安装协议</p></li>
            <li class=""><span class="num">2</span>
                <p class="name">检测安装环境</p></li>
            <li class=""><span class="num">3</span>
                <p class="name">可写检测</p></li>
            <li class="current"><span class="num">4</span>
                <p class="name">开始安装</p></li>
            <li class=""><span class="num">5</span>
                <p class="name">完成安装</p></li>
        </ul>

    </div>
</div>
<div class="db-content">

    <fieldset>
        <legend>数据库配置信息</legend>
        <table border="1" cellpadding="true" cellspacing="true">

            <tr>
                <td>数据库地址<p style="color: red">*</p></td>
                <td><input type="text" required name="dbhost" placeholder="请输入数据库地址"></td>

                <td>数据库端口<p style="color: red">*</p></td>
                <td><input type="text" required name="dbport" placeholder="请输入数据库端口"></td>
            </tr>
            <tr>
                <td>数据库名称<p style="color: red">*</p></td>
                <td><input type="text" required name="dbname" placeholder="请输入数据库名称"></td>

                <td>数据库账号<p style="color: red">*</p></td>
                <td><input type="text" required name="dbuser" placeholder="请输入数据库账号"></td>
            </tr>
            <tr>
                <td>数据库密码<p style="color: red">*</p></td>
                <td><input type="text" required name="dbpass" placeholder="请输入数据库密码"></td>

                <td>数据库表前缀<p style="color: red">*</p></td>
                <td><input type="text" required name="dbprefix" value="lee_" placeholder="请输入数据库表前缀"></td>
            </tr>
            </tbody>
        </table>
    </fieldset>
    <fieldset>
        <legend>管理员登录信息配置</legend>
        <table border="1" cellpadding="true" cellspacing="true">

            <tr>
                <td>管理员账号<p style="color: red">*</p></td>
                <td><input type="text" required name="username" placeholder="请输入管理员账号"></td>

                <td>管理员密码<p style="color: red">*</p></td>
                <td><input type="text" required name="password" placeholder="请输入管理员密码"></td>
            </tr>
            <tr>
                <td>邮箱地址<p style="color: red">*</p></td>
                <td><input type="text" required name="email" placeholder="请输入邮箱地址"></td>
                <td>联系电话</td>
                <td><input type="text" name="phone" placeholder="请输入联系电话"></td>
                <!--
                                <td>姓名</td>
                                <td><input type="text" name="name" placeholder="请输入姓名"></td>-->
            </tr>

            </tbody>
        </table>
    </fieldset>
    <div style="margin-top: 5px;float: right;font-size: 13px; color: #1c6ca1"><input type="checkbox" name="isTestData">
        是否安装测试数据
    </div>
</div>
<script type="text/javascript">
    function submit_next() {
        let flag = true;
        let data = {};
        let pattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        let port_pattern = /^[0-9]*$/;
        let isTestData = $("input[type='checkbox']").prop("checked");
        data["isTestData"] = isTestData ? 2 : 1;
        $("input[type='text']").each((index, item) => {
            let name = item["name"];
            let val = item["value"];
            if (item["required"] && !item["value"]) {
                alert(item["placeholder"]);
                item.focus();
                flag = false;
            }
            if (name == "password" && (val.length < 6 || val.length > 18)) {
                alert("管理员密码长度必须是6-18位");
                item.focus();
                flag = false;
            }
            if (name == "email" && !pattern.test(val)) {
                alert("请输入正确格式的邮箱地址");
                item.focus();
                flag = false;
            }
            if (name == "dbport" && !port_pattern.test(val)) {
                alert("数据库端口只能是数字");
                item.focus();
                flag = false;
            }
            if (!flag) {
                return flag;
            }
            data[item["name"]] = item["value"];
            //  console.log(item["name"],item["value"]);
        });

        if (flag) {
            $.post("index.php?step=install", data, function (redata) {
                if (redata == "ok") {
                    window.location.href = "step5.php";
                } else {
                    alert(redata);
                }

            });

        }

    }
</script>
<div class="btn_wrap">
    <input name=""
           type="button"
           class="next_btn"
           value="下一步"
           onclick="submit_next()"/><input
            name="" type="button" class="prev_btn" value="上一步" onclick="window.location.href='?step=step3'"/>
    <div class="cl"></div>
</div>
<div class="footer">Powered By LeeCms 版权所有 &copy; 2020-2022, All right reserved.</div>
</body>
</html>